package cn.tedu.jsd2205the.back.end.project.controller;


import cn.tedu.jsd2205the.back.end.project.pojo.dto.UserLoginDTO;
import cn.tedu.jsd2205the.back.end.project.pojo.dto.UserRegisterDTO;
import cn.tedu.jsd2205the.back.end.project.pojo.entity.User;
import cn.tedu.jsd2205the.back.end.project.restful.JsonResult;
import cn.tedu.jsd2205the.back.end.project.service.IUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@Api(tags = "01.用户模块")
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    /**
     * 注册
     * @param userRegisterDTO
     * @return
     */
    @ApiOperation("用户注册")
    @ApiOperationSupport(order = 80)
    @PostMapping("/reg")
    public JsonResult<Void>reg(@Valid UserRegisterDTO userRegisterDTO){
        log.debug("开始处理【用户注册】的请求，参数：{}", userRegisterDTO);
        userService.reg(userRegisterDTO);
        return JsonResult.success();
    }

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public JsonResult<Void> login(UserLoginDTO userLoginDTO){
        User login = userService.Login(userLoginDTO);
        return JsonResult.success("登录成功");
    }


}
